﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace KM.Framework.Utility
{
    /// <summary>
    /// 隐藏转换器(bool转为显示隐藏值，true的时候隐藏)
    /// </summary>
    public class CollapsedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string result = "Hidden";

            switch (value)
            {
                case true:
                    result = "Collapsed";
                    break;
                case false:
                    result = "Visible";
                    break;
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>
    /// 显示转换器(bool转为显示隐藏值，true的时候显示)
    /// </summary>
    public class VisibleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Visibility result = Visibility.Hidden;

            switch (value)
            {
                case true:
                    result = Visibility.Visible;
                    break;
                case false:
                    result = Visibility.Collapsed;
                    break;
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class DivideConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrWhiteSpace(parameter + ""))
                throw new ArgumentNullException(nameof(parameter), "parameter can not be null or empty");

            if (!int.TryParse(parameter + "", out int divideValue))
                throw new ArgumentException("parameter must be int type", nameof(parameter));

            if (!double.TryParse(value + "", out double originValue))
                throw new ArgumentException("value must can be convert to double type", nameof(value));

            return originValue / divideValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
